package com.stefan.lession04;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 主窗口
 */
public class DialogDemo extends JFrame {

    public DialogDemo(){
        this.setVisible(true);
        this.setSize(800,800);
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        // JFrame 放东西，容器
        Container contentPane = this.getContentPane();
        // 绝对布局
        contentPane.setLayout(null);

        // 按钮
        JButton jButton = new JButton("弹出对话框");
        jButton.setBounds( 30,30,200,50);

        // 点击这个按钮的时候，弹出一个弹窗
        jButton.addActionListener(new ActionListener() {// 监听器
            @Override
            public void actionPerformed(ActionEvent e) {
                // 弹窗
                new MyDialog();
            }
        });

        contentPane.add(jButton);
    }

    public static void main(String[] args) {
        new DialogDemo();
    }
}

/**
 * 弹窗的窗口
 */
class MyDialog extends JDialog{

    public MyDialog(){
        this.setVisible(true);
        this.setBounds(100,100,500,500);
        // 已有默认
        // this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

        Container contentPane = this.getContentPane();
        contentPane.setLayout(null);
        contentPane.add(new JLabel("弹窗窗口测试"));
    }
}
